/**
 * Created by duwei on 2019/1/2.
 */
var BuyEmojiWindow = Window.extend({
    _ccsFileName : chat.res.BuyTishi_json,
    initWindow: function (content, onOk, onCancel) {
        this._super();
        var self = this;
        this._onOkCallBack = onOk;
        this._onCancelCallBack = onCancel;

        this._content = content || '';
        if(cc.sys.localStorage.getItem('BuyTishiGouXuan_' + this._getTodayTime()) == 1){
            self._clickOk();
            return;
        }
        self._nodeList['root.panel.lb_content'].setString(content);
        self._nodeList['root.panel.CheckBox'].setSelected(cc.sys.localStorage.getItem('BuyTishiGouXuan_' + self._getTodayTime()) == 1);
        self._nodeList['root.panel.CheckBox'].addEventListener(function (_, type) {
            var gouxuan = type == ccui.CheckBox.EVENT_SELECTED;
            cc.sys.localStorage.setItem('BuyTishiGouXuan_'+ self._getTodayTime(), gouxuan ? 1 : 0);
        });
    },

    _initClickListeners: function () {
        this._super();
        this._clickListeners = {
            'root.panel.btn_ok': '_clickOk',
            'root.panel.btn_cancel': '_clickCancel'
        };
    },

    _clickOk:function(){
        if (this._onOkCallBack)
            this._onOkCallBack();
        this.removeFromParent(true);
    },
    _clickCancel:function(){
        if (this._onCancelCallBack)
            this._onCancelCallBack();
        this.removeFromParent(true);
    },


    _getTodayTime:function () {
        var mydate = new Date();
        var year = mydate.getFullYear();
        var month =  mydate.getMonth()+1;
        var today = mydate.getDate();
        return year + "_" +month+"_"+today;
    },
});